package _interview75;

/**
 * 345. 反转字符串中的元音字母
 */
public class No345 {
    public String reverseVowels(String s) {
        char[] charArray = s.toCharArray();
        int left = 0, right = s.length() - 1;
        for (; left < right; left++) {
            if (isVowel(s.charAt(left))) {
                for (; left < right; right--) {
                    if (isVowel(s.charAt(right))) {
                        char temp = charArray[left];
                        charArray[left] = charArray[right];
                        charArray[right] = temp;
                        right--;
                        break;
                    }
                }
            }
        }
        return new String(charArray);
    }

    private boolean isVowel(char ch) {
        return "aeiouAEIOU".indexOf(ch) >= 0;
    }
}
